package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QxbmDistrict;
import com.ruoyi.system.service.IQxbmDistrictService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 行政区Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/district")
public class QxbmDistrictController extends BaseController
{
    @Autowired
    private IQxbmDistrictService qxbmDistrictService;

    /**
     * 查询行政区列表
     */
    @PreAuthorize("@ss.hasPermi('system:district:list')")
    @GetMapping("/list")
    public AjaxResult list(QxbmDistrict qxbmDistrict)
    {
        List<QxbmDistrict> list = qxbmDistrictService.selectQxbmDistrictList(qxbmDistrict);
        return success(list);
    }

    /**
     * 导出行政区列表
     */
    @PreAuthorize("@ss.hasPermi('system:district:export')")
    @Log(title = "行政区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QxbmDistrict qxbmDistrict)
    {
        List<QxbmDistrict> list = qxbmDistrictService.selectQxbmDistrictList(qxbmDistrict);
        ExcelUtil<QxbmDistrict> util = new ExcelUtil<QxbmDistrict>(QxbmDistrict.class);
        util.exportExcel(response, list, "行政区数据");
    }

    /**
     * 获取行政区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:district:query')")
    @GetMapping(value = "/{districtId}")
    public AjaxResult getInfo(@PathVariable("districtId") Long districtId)
    {
        return success(qxbmDistrictService.selectQxbmDistrictByDistrictId(districtId));
    }

    /**
     * 新增行政区
     */
    @PreAuthorize("@ss.hasPermi('system:district:add')")
    @Log(title = "行政区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QxbmDistrict qxbmDistrict)
    {
        return toAjax(qxbmDistrictService.insertQxbmDistrict(qxbmDistrict));
    }

    /**
     * 修改行政区
     */
    @PreAuthorize("@ss.hasPermi('system:district:edit')")
    @Log(title = "行政区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QxbmDistrict qxbmDistrict)
    {
        return toAjax(qxbmDistrictService.updateQxbmDistrict(qxbmDistrict));
    }

    /**
     * 删除行政区
     */
    @PreAuthorize("@ss.hasPermi('system:district:remove')")
    @Log(title = "行政区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{districtIds}")
    public AjaxResult remove(@PathVariable Long[] districtIds)
    {
        return toAjax(qxbmDistrictService.deleteQxbmDistrictByDistrictIds(districtIds));
    }
}
